﻿using System;

namespace Ndns.Packet
{
    /// <summary>
    /// DNS的类型。
    /// </summary>
    public enum DnsClass : ushort
    {
        Internet = 0x0001,
    }

    /// <summary>
    /// 表示DNS的记录类型。
    /// </summary>
    public enum DnsRecordType : ushort
    {
        A = 1,

        NS = 2,

        CNAME = 5,

        SOA = 6,

        //WKS = 11,

        PTR = 12,

        //HINFO = 13,

        //MINFO = 14,

        MX = 15,

        TXT = 16,

        AAAA = 28,

        //SRV = 33,

        ANY = 255
    }

    /// <summary>
    /// DNS数据包的标志。
    /// </summary>
    [Flags]
    public enum DnsPacketFlag : ushort
    {
        /// <summary>
        /// 表示这是一个查询数据包，与ResponsePacket相对应。
        /// </summary>
        QueryPacket = 0,

        /// <summary>
        /// 表示这是一个应答数据包，与QueryPacket相对应。
        /// </summary>
        ResponsePacket = 0x8000,

        /// <summary>
        /// 应答数据包中表明服务器不是域的权威，与ServerAuthoritative相对应。
        /// </summary>
        ServerNotAuthoritative = 0,

        /// <summary>
        /// 应答数据包中表明服务器是域的权威，与ServerNotAuthoritative相对应。
        /// </summary>
        ServerAuthoritative = 0x400,

        /// <summary>
        /// 消息没有被截断，与Truncated相对应。
        /// </summary>
        NotTruncated = 0,

        /// <summary>
        /// 消息被截断，与NotTruncated相对应。
        /// </summary>
        Truncated = 0x200,

        /// <summary>
        /// 请求服务器不要递归查询，与RecursionDesired相对应。
        /// </summary>
        RecursionNotDesired = 0,

        /// <summary>
        /// 允许服务器进行递归查询，与RecursionNotDesired相对应。
        /// </summary>
        RecursionDesired = 0x100,

        /// <summary>
        /// 应答数据包中表示服务器无法进行递归查询，与RecursionAvailable相对应。
        /// </summary>
        RecursionNotAvailable = 0,

        /// <summary>
        /// 应答数据包中表示服务器可以进行递归查询，与RecursionNotAvailable相对应。
        /// </summary>
        RecursionAvailable = 0x80,

        //.... .... .0.. .... = Z: reserved (0)

        /// <summary>
        /// 应答数据包中表示应答没有经过权威认证，与AnswerAuthenticated相对应。
        /// </summary>
        AnswerNotAuthenticated = 0,

        /// <summary>
        /// 应答数据包中表示应答已经经过权威认证，与AnswerNotAuthenticated相对应。
        /// </summary>
        AnswerAuthenticated = 0x20,

        /// <summary>
        /// 请求数据包中表示客户端不愿意接受未认证的数据。
        /// </summary>
        DontAcceptNonAuthenticatedData = 0,

        /// <summary>
        /// 请求数据包中表示客户端愿意接受未认证的数据。
        /// </summary>
        AcceptNonAuthenticatedData = 0x10,

        MaxValue = UInt16.MaxValue,
        MinValue = UInt16.MinValue,
    }

    public enum DnsOpCode : byte
    {
        Query = 0,

        Status = 2,

        Notify = 4,

        Update = 5
    }

    public enum DnsReplyCode : byte
    {
        NoError = 0,

        FormatError = 1,

        ServerFailure = 2,

        NonExistentDomain = 3,

        NotImplemented = 4,

        QueryRefused = 5,

        /// <summary>
        /// Name Exists when it should not
        /// </summary>
        YXDomain = 6,

        /// <summary>
        /// RR Set Exists when it should not
        /// </summary>
        YXRRSet = 7,

        /// <summary>
        /// RR Set that should exist does not
        /// </summary>
        NXRRSet = 8,

        /// <summary>
        /// Server Not Authoritative for zone
        /// </summary>
        ServerNotAuth = 9,

        NotAuth = 10,

        /// <summary>
        /// Name not contained in zone
        /// </summary>
        NotZone = 11,
    }
}
